Skip to content

fix: resolve "invalid reference" error in contributors workflow (#12) - #13

Merged
udaycodespace merged 1 commit into
udaycodespace:mainfrom
Aryanbuha890:fix/12-contributors-workflow-invalid-reference
Jul 17, 2026
Merged

fix: resolve "invalid reference" error in contributors workflow (#12)#13
udaycodespace merged 1 commit into
udaycodespace:mainfrom
Aryanbuha890:fix/12-contributors-workflow-invalid-reference

Conversation

@Aryanbuha890

Copy link
Copy Markdown
Contributor

🐛 Fixes #12

What was broken

After PR #11 merged, the contributors workflow failed every time with:

image

fatal: invalid reference: feat/issue-10-readme-contributors Error: Invalid status code: 128

Root Cause

On pull_request: closed events, GitHub checks out the merged PR's source branch
(e.g. feat/issue-10-readme-contributors) — not main. After the PR merges, that source
branch gets deleted. So when git-auto-commit-action tried to push a README update back
to that deleted branch ref, it failed with the invalid reference error.


Fix — 2 lines changed in .github/workflows/update-contributors.yml

Before:

- uses: actions/checkout@v4
  with:
    fetch-depth: 0          # ❌ checks out deleted PR source branch

- uses: stefanzweifel/git-auto-commit-action@v5
  with:
    commit_message: "docs: update contributors in README [skip ci]"
    file_pattern: "README.md"
                            # ❌ no branch specified → pushes to deleted ref


**After:**

- uses: actions/checkout@v4
  with:
    ref: main               # ✅ always checks out main
    fetch-depth: 0

- uses: stefanzweifel/git-auto-commit-action@v5
  with:
    commit_message: "docs: update contributors in README [skip ci]"
    file_pattern: "README.md"
    branch: main            # ✅ always commits back to main


**Expected Flow After Fix :**

PR merged into main
  → pull_request: closed fires
  → checkout ref: main ✅
  → Node script updates README.md
  → git-auto-commit-action commits to branch: main ✅
  → README updated, no errors in Actions log ✅

…despace#12)

On pull_request: closed events, the runner checks out the merged PR's
source branch (e.g. feat/issue-10-readme-contributors) which is deleted
after merge. git-auto-commit-action then fails with:
  fatal: invalid reference: feat/issue-10-readme-contributors
Fix:
- Add ref: main to actions/checkout so the job always works on main
- Add branch: main to git-auto-commit-action so commits always land on main
@github-actions

Copy link
Copy Markdown

🚨 @Aryanbuha890, pull requests modifying GitHub actions/workflows from forks are automatically closed for repository security. Maintainers will review and manually implement updates if needed.

@github-actions github-actions Bot closed this Jul 17, 2026
@Aryanbuha890

Copy link
Copy Markdown
Contributor Author

@udaycodespace Please check it and verify it, here i set the referene of main in this file for automate.

@udaycodespace udaycodespace reopened this Jul 17, 2026
@udaycodespace

Copy link
Copy Markdown
Owner

@udaycodespace Please check it and verify it, here i set the referene of main in this file for automate.

I will review tonight!

@udaycodespace udaycodespace added ECSoC26 Required label for a PR to be eligible for Sentinel scoring ECSoC26-L1 Easy difficulty, auto-assigned by Sentinel — 5 points and removed workflows labels Jul 17, 2026
@udaycodespace

Copy link
Copy Markdown
Owner

@Aryanbuha890 fix works, verified both lines. lgtm!

  1. One thing though: write your own PR descriptions going forward.
  2. Using AI to help is fine, but paste it as-is and it stops looking like your own understanding of the fix, that's why feat: automate README contributors section using GitHub Actions (#10) #11 got marked L1 instead of L2, not the code.
  3. You're executing the assigned issues fine. Just own the write-up part too.

@udaycodespace
udaycodespace merged commit 95b691b into udaycodespace:main Jul 17, 2026
5 checks passed
@ecsoc-sentinel ecsoc-sentinel Bot added ECSoC26-L1 Easy difficulty, auto-assigned by Sentinel — 5 points and removed ECSoC26-L1 Easy difficulty, auto-assigned by Sentinel — 5 points labels Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ECSoC26-L1 Easy difficulty, auto-assigned by Sentinel — 5 points ECSoC26 Required label for a PR to be eligible for Sentinel scoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: contributors workflow fails with "invalid reference" after merge to main

2 participants